package com.hgc.ch01.base;

import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

/**
 * Created by 01367627 on 2019/6/14.
 */
public class PrintThreads {

    public static void printThreads(){
        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
        long[] allThreadIds = threadMXBean.getAllThreadIds();
        for(long threadId : allThreadIds){
            ThreadInfo threadInfo = threadMXBean.getThreadInfo(threadId);
            System.out.println("线程名称：" + threadInfo.getThreadName());
            System.out.println("线程状态：" + threadInfo.getThreadState());
            System.out.println("-----------------");
        }
    }

    public static void main(String[] args) throws IOException {
        printThreads();
    }
}
